Computer Science Engineering (CSE) Exam  >  Computer Science Engineering (CSE) Questions  >  Consider the following code fragment:if (fork... Start Learning for Free
Consider the following code fragment:
if (fork() == 0)
{ a = a + 5; printf("%d,%dn", a, &a); }
else { a = a –5; printf("%d, %dn", a, &a); }
Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?
  • a)
    u = x + 10 and v = y
  • b)
    u = x + 10 and v != y
  • c)
    u + 10 = x and v = y
  • d)
    u + 10 = x and v != y
Correct answer is option 'C'. Can you explain this answer?
Verified Answer
Consider the following code fragment:if (fork() == 0){ a = a + 5; prin...
fork() returns 0 in child process and process ID of child process in parent process. In Child (x), a = a + 5 In Parent (u), a = a – 5; Therefore x = u + 10. The physical addresses of ‘a’ in parent and child must be different. But our program accesses virtual addresses (assuming we are running on an OS that uses virtual memory). The child process gets an exact copy of parent process and virtual address of ‘a’ doesn’t change in child process. Therefore, we get same addresses in both parent and child. See this run for example.
View all questions of this test
Most Upvoted Answer
Consider the following code fragment:if (fork() == 0){ a = a + 5; prin...
"a = %d\n", a);}

In this code fragment, the fork() function is used to create a new process. The fork() function returns a value to the parent process and the child process. In this case, if the fork() function returns 0, it means that the code is being executed in the child process.

Inside the if statement, the variable "a" is being modified by adding 5 to its current value. Then, the printf() function is used to print the value of "a".

If the fork() function returns a non-zero value, it means that the code is being executed in the parent process. Therefore, the code inside the if statement will not be executed by the parent process.

Overall, this code fragment creates a child process and modifies the value of "a" in the child process. The value of "a" in the parent process remains unchanged.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer?
Question Description
Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? for Computer Science Engineering (CSE) 2024 is part of Computer Science Engineering (CSE) preparation. The Question and answers have been prepared according to the Computer Science Engineering (CSE) exam syllabus. Information about Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? covers all topics & solutions for Computer Science Engineering (CSE) 2024 Exam. Find important definitions, questions, meanings, examples, exercises and tests below for Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer?.
Solutions for Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? in English & in Hindi are available as part of our courses for Computer Science Engineering (CSE). Download more important topics, notes, lectures and mock test series for Computer Science Engineering (CSE) Exam by signing up for free.
Here you can find the meaning of Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? defined & explained in the simplest way possible. Besides giving the explanation of Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer?, a detailed solution for Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? has been provided alongside types of Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? theory, EduRev gives you an ample number of questions to practice Consider the following code fragment:if (fork() == 0){ a = a + 5; printf("%d,%dn", a, &a); }else { a = a –5; printf("%d, %dn", a, &a); }Let u, v be the values printed by the parent process, and x, y be the values printed by the child process. Which one of the following is TRUE?a)u = x + 10 and v = yb)u = x + 10 and v != yc)u + 10 = x and v = yd)u + 10 = x and v != yCorrect answer is option 'C'. Can you explain this answer? tests, examples and also practice Computer Science Engineering (CSE) tests.
Explore Courses for Computer Science Engineering (CSE) exam

Top Courses for Computer Science Engineering (CSE)

Explore Courses
Signup for Free!
Signup to see your scores go up within 7 days! Learn & Practice with 1000+ FREE Notes, Videos & Tests.
10M+ students study on EduRev